package com.asset.dispoal.menu;

import com.asset.dispoal.menu.api.GbMenuService;
import com.asset.dispoal.menu.dto.requset.GbMenuRequest;
import com.asset.dispoal.menu.dto.response.GbMenuResponse;
import com.asset.dispoal.role.dto.GbRoleRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.List;

/**
 * @author qr
 * @date 2022/2/28$
 */
@RestController
@Api(value = "菜单配置", tags = "菜单配置")
@RequestMapping("sys/menu")
public class MenuController {


    @Autowired
    GbMenuService gbMenuService;

    //    @Permission(code = "menu:add")
    @PostMapping("insert")
    @ApiOperation(value = "添加菜单", notes = "添加菜单")
    public Result insert(@RequestBody GbMenuRequest request) {
        gbMenuService.insert(request);
        return Result.ok();
    }


    //    @Permission(code = "menu:update")
    @PostMapping("update")
    @ApiOperation(value = "修改菜单", notes = "修改菜单")
    public Result update(@RequestBody GbMenuRequest request) {
        gbMenuService.update(request);
        return Result.ok();
    }

    //    @Permission(code = "menu:del")
    @PostMapping("delete")
    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    public Result delete(@RequestBody String id) {
        gbMenuService.delete(id);
        return Result.ok();
    }


    @PostMapping("queryMenu")
    @ApiOperation(value = "查询全部菜单", notes = "查询全部菜单")
    public Result<List<GbMenuResponse>> queryMenu(@RequestBody GbMenuRequest request) {
        return gbMenuService.queryTreeAll(request);
    }

    @PostMapping("selectMenu")
    @ApiOperation(value = "选中菜单", notes = "选中菜单")
    public Result selectMenu(@RequestBody List<String> ids) {
        return gbMenuService.selectMenu(ids);
    }

    @GetMapping("companyMenu")
    @ApiOperation(value = "根据公司类型查询菜单", notes = "根据公司类型查询菜单")
    public Result<List<GbMenuResponse>> companyMenu(String companyType) {
        return gbMenuService.companyMenu(companyType);

    }


    @GetMapping("companyMenuById")
    @ApiOperation(value = "根据公司id查询菜单", notes = "根据公司id查询菜单")
    public Result<List<GbMenuResponse>> companyMenuById(String companyId) {
        return gbMenuService.companyMenuById(companyId);

    }

    @GetMapping("defaultRoleMenu")
    @ApiOperation(value = "(通用默认设置)根据角色查询菜单", notes = "(通用默认设置)根据角色查询菜单")
    public Result<List<GbMenuResponse>> defaultRoleMenu(String role, String companyType) {
        return gbMenuService.defaultRoleMenu(role, companyType);

    }


    @PostMapping("roleMenu")
    @ApiOperation(value = "根据角色查询菜单", notes = "根据角色查询菜单")
    public Result<List<GbMenuResponse>> roleMenu(@RequestBody GbRoleRequest request) {
        return gbMenuService.roleMenu(request);

    }


}
